<template>
    <div style="height:100%;width:100%;">
        <bar class="bar" @on-back="$router.back()" title="IC卡信息"> </bar>
        <group>
            <mu-input label="单位" label-class="my-name" v-model="newValue" class="my-edit-name"></mu-input>
        </group>
        <div class="my-input">
            <x-button class="login-submit" @click.native="handle">确定</x-button>
        </div>
    </div>
</template>

<script>
    import {mapState} from 'vuex'
    import {mapMutations} from 'vuex'
    import VUEX_NAME from '../../../store/constants.vue'
    import {
        lang
    } from 'muka'
    import {
        Bar,
        MInput
    } from 'muka-ui'
    import {
        Group,
        XButton
    } from 'vux'
    export default {
        name: 'editName',
        components: {
            Bar,
            'mu-input': MInput,
            Group,
            XButton
        },
        data: function () {
            return {
                newValue: '',
                item: null,
            }
        },
        created: function () {
            if(this.$route.params.which === "1")
            {
                this.item = this.cardList[this.$route.params.index]
            }
            else
            {
                this.item = this.searchCardList[this.$route.params.index]
            }

            this.newValue = this.item.company
        },
        computed: mapState([
            VUEX_NAME.cardList,
            VUEX_NAME.searchCardList

        ]),
        methods: {
            ...mapMutations([
                VUEX_NAME.cCardList,
                VUEX_NAME.cSearchCardList

            ]),
            handle: function () {
                if (!this.newValue) {
                    this.$vux.toast.show({
                        text: '请输入单位信息',
                        type: 'text',
                        position: 'middle'
                    })
                } else if (this.newValue === this.item.company) {
                    this.$vux.toast.show({
                        text: '没有做任何修改',
                        type: 'text',
                        position: 'middle'
                    })
                } else {
                    this.$ajax(
                        'card/editCard',
                        {
                            cardId: this.item.cardId,
                            company: this.newValue
                        },
                        (content) => {
                            this.item.company = this.newValue
                            this.$router.back()
                        }, true)
                }

            }
        }
    }

</script>
